package baseline;


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

import common.BaselineTagger;
import common.Eval;
import common.CorpusProcessor;

public class BaselineAcc {
	public static void main(String[] args) {
		System.out.println("Applying the Baseline tagger to the development set...");
		// Read the words (normalized) and the pos tags from the training set
		ArrayList<String> words = new ArrayList<String>();
		ArrayList<String> pos = new ArrayList<String>();
		try {
			File file = new File("CoNLL2009-ST-English-train-pos.txt");
			BufferedReader br = new BufferedReader(new FileReader(file));
			String line = null;
			while ((line = br.readLine()) != null) {
		    	if(line.equals("")) continue;
		        String[] cols = line.split("\t");
		        words.add(cols[2]);
		        pos.add(cols[4]);
		    }
		} catch (IOException x) {
		    System.err.format("IOException: %s%n", x);
		}
		
		// Process the training set and initialize the taggers with the data
		CorpusProcessor cp = new CorpusProcessor();
		cp.process(words, pos);
		BaselineTagger bt = new BaselineTagger(cp.getWordCounts());
		
		// Read the words (normalized) and the pos tags from the development set (pos needed for evaluation of taggers)
		words.clear();
		pos.clear();
		
		try {
			File file = new File("CoNLL2009-ST-English-development-pos.txt");
			BufferedReader br = new BufferedReader(new FileReader(file));
			String line = null;
			while ((line = br.readLine()) != null) {
		    	if(line.equals("")) continue;
		        String[] cols = line.split("\t");
		        words.add(cols[2]);
		        pos.add(cols[4]);
		    }
		} catch (IOException x) {
		    System.err.format("IOException: %s%n", x);
		}
		
		// Apply and evaluate the baseline tagger on the development set
		ArrayList<String> pposBaseline = bt.tag(words);
		
		Eval e1 = new Eval(pos, pposBaseline);
		System.out.println("Done tagging. Accuracy was "+ e1.pposAccuracy());
	}
}
